<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Integer Sort</title>
<link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../../index.html" title="Boost.Sort">
<link rel="up" href="../sort_hpp.html" title="Spreadsort">
<link rel="prev" href="../sort_hpp.html" title="Spreadsort">
<link rel="next" href="float_sort.html" title="Float Sort">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../sort_hpp.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../sort_hpp.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="float_sort.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="sort.single_thread.spreadsort.sort_hpp.integer_sort"></a><a class="link" href="integer_sort.html" title="Integer Sort">Integer
          Sort</a>
</h5></div></div></div>
<p>
            <code class="literal"><code class="computeroutput"><a class="link" href="../../../../boost/sort/spreadsort/integer_sort_idm1895.html" title="Function template integer_sort">integer_sort</a></code></code>
            is a fast templated in-place hybrid radix/comparison algorithm, which
            in testing tends to be roughly 50% to 2X faster than <a href="http://en.cppreference.com/w/cpp/algorithm/sort" target="_top">std::sort</a>
            for large tests (&gt;=100kB). Worst-case performance is <span class="emphasis"><em>𝑶(N
            * (log2(range)/s + s))</em></span>, so <code class="literal"><code class="computeroutput"><a class="link" href="../../../../boost/sort/spreadsort/integer_sort_idm1895.html" title="Function template integer_sort">integer_sort</a></code></code>
            is asymptotically faster than pure comparison-based algorithms. <span class="emphasis"><em>s</em></span>
            is <span class="emphasis"><em>max_splits</em></span>, which defaults to 11, so its worst-case
            with default settings for 32-bit integers is <span class="emphasis"><em>𝑶(N * ((32/11)</em></span>
            slow radix-based iterations + 11 fast comparison-based iterations).
          </p>
<p>
            Some performance plots of runtime vs. n and log2(range) are provided
            below:
          </p>
<p>
            <a href="../../../../../../doc/graph/windows_integer_sort.htm" target="_top">Windows Integer
            Sort</a>
          </p>
<p>
            <a href="../../../../../../doc/graph/osx_integer_sort.htm" target="_top">OSX integer Sort</a>
          </p>
<div class="section">
<div class="titlepage"><div><div><h6 class="title">
<a name="sort.single_thread.spreadsort.sort_hpp.integer_sort.integersort_examples"></a><a class="link" href="integer_sort.html#sort.single_thread.spreadsort.sort_hpp.integer_sort.integersort_examples" title="Integer Sort Examples">Integer
            Sort Examples</a>
</h6></div></div></div>
<p>
              See <a href="../../../../../../example/rightshiftsample.cpp" target="_top">rightshiftsample.cpp</a>
              for a working example of using rightshift, using a user-defined functor:
            </p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">rightshift</span> <span class="special">{</span>
  <span class="keyword">inline</span> <span class="keyword">int</span> <span class="keyword">operator</span><span class="special">()(</span><span class="identifier">DATA_TYPE</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">offset</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">x</span> <span class="special">&gt;&gt;</span> <span class="identifier">offset</span><span class="special">;</span> <span class="special">}</span>
<span class="special">};</span>
</pre>
<p>
              Other examples:
            </p>
<p>
              <a href="../../../../../../example/keyplusdatasample.cpp" target="_top">Sort structs using
              an integer key.</a>
            </p>
<p>
              <a href="../../../../../../example/reverseintsample.cpp" target="_top">Sort integers in reverse
              order.</a>
            </p>
<p>
              <a href="../../../../../../example/mostlysorted.cpp" target="_top">Simple sorting of integers;
              this case is a performance test for integers that are already mostly
              sorted.</a>
            </p>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2014-2017 Steven
      Ross, Francisco Tapia, Orson Peters<p>
        Distributed under the <a href="http://boost.org/LICENSE_1_0.txt" target="_top">Boost
        Software License, Version 1.0</a>.
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../sort_hpp.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../sort_hpp.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="float_sort.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
